#!/usr/bin/env bash
# vim: fdm=marker fmr=[[[,]]] cms=\ #%s

function usage()
{ #[[[
    echo "Usage: $(basename $0) {SVC1 SVC2 SVC3 ...} "
} #]]]

function main()
{ #[[[
    if [[ $# == 0 ]]
    then
        usage
        return 1
    fi

    if [[ -z $SVCENV_DIR ]]
    then
        echo "Error: SVCENV_DIR not set"
        return 1
    fi
    if [[ -z $SVCENV_CNFG ]]
    then
        echo "Error: SVCENV_CNFG not set"
        return 1
    fi

    if [[ -e $SVCENV_DIR/bin/svc ]]
    then
        if [[ ! -d $SVCENV_DIR/bin/svc ]]
        then
            echo "Error: $SVCENV_DIR/bin/svc not directory"
            return 1
        fi
    else
        mkdir $SVCENV_DIR/bin/svc
    fi 

    cd $SVCENV_DIR/src/svc
    cp -f svr.inc $SVCENV_DIR/bin/svc
    while [[ ! -z $1 ]]
    do
        svc=$1
        if [[ ! -f ${svc}.inc ]]
        then
            echo "Error: ${svc}.inc not found"
            return 1
        fi
        cp -f ${svc}.inc $SVCENV_DIR/bin/svc
        shift
    done
    downenv
    bootenv

    return 0
} #]]]

main $@
exit $?
